package com.ynu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ynu.bean.PageBean;
import com.ynu.bean.query.GoodsQuery;
import com.ynu.bean.vo.GoodsVO;
import com.ynu.converter.GoodsConverter;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import com.ynu.mapper.GoodsMapper;
import com.ynu.bean.entity.Goods;
import com.ynu.service.GoodsService;
/**
*  模块名称：
*  模块类型：
*  编码人：迟宽席
*  创建时间：2023/2/28
*  联系电话：18388068273
*/
@Service
public class GoodsServiceImpl implements GoodsService{
    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private GoodsConverter goodsConverter;

    @Override
    public PageBean<GoodsVO> getGoodsByConditionWithPage(GoodsQuery goodsQuery) {
        Page<Goods> page = null;
        // 分页
        Integer pageNum = goodsQuery.getPageNum();
        Integer pageSize = goodsQuery.getPageSize();
        if (pageNum != null && pageSize != null) {
            page = PageHelper.startPage(pageNum, pageSize);
        }

        //查询数据
        goodsMapper.selectGoodsByCondition(goodsQuery);

        //将Page转换成PageBean对象
        PageBean<Goods> goodsPageBean = PageBean.trans(page);

        //将PageBean<Goods>转换成PageBean<GoodsVO>
        PageBean<GoodsVO> goodsVOPageBean = goodsConverter.goodsPageBean2GoodsVOPageBean(goodsPageBean);

        return goodsVOPageBean;
    }

    @Override
    public Goods getByPrimaryKey(Long id) {
        return goodsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return goodsMapper.deleteByPrimaryKey(id);
    }


    @Override
    public int insertSelective(Goods record) {
        return goodsMapper.insertSelective(record);
    }


    @Override
    public int updateByPrimaryKeySelective(Goods record) {
        return goodsMapper.updateByPrimaryKeySelective(record);
    }


    public void selectByPrimaryKey(Long id) {

    }
}
